package com.fs.alert.socketio;

import com.corundumstudio.socketio.SocketIOServer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fs.alert.domain.po.Alert;
import com.fs.common.domain.Result;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.time.LocalDateTime;

@Service
@Slf4j
@RequiredArgsConstructor
public class SocketIOServerManager {
    private final SocketIOServer server;

    @PostConstruct
    private void start() {
        server.start();

        // 添加连接监听事件
        server.addConnectListener(client -> {
            log.info("客服端已连接: {}", client.getSessionId());
        });

        server.addDisconnectListener(client -> {
            log.info("客户端断开连接: {}", client.getSessionId());
        });
    }

    @PreDestroy
    private void stop() {
        if (server != null) {
            server.stop();
        }
    }
}
